package praktikumid.w09.p2;

/**
 * Frame example (with small string functionality example).
 * @author Ago
 *
 */
public class Main {

	/**
	 * main-method.
	 * @param args arguments.
	 */
	public static void main(String[] args) {
		//parseString();
		MyFrame f = new MyFrame();
		f.setVisible(true);
	}

	/**
	 * Examples with main string methods.
	 */
	public static void parseString() {
		// indices start from 0s
		
		//                    11
		//          012345678901
		String s = "Hello world!";
		
		// character at specified index
		System.out.println(s.charAt(7));
		
		// Finds the index of the first occurrence
		// of the specified string. The returned
		// index indicates the start of the string.
		System.out.println(s.indexOf("world"));
		System.out.println(s.indexOf("Hello"));
		// If string is not found, -1 is returned.
		System.out.println(s.indexOf("maailm"));

		// indexOf with 2 arguments
		System.out.println(s.indexOf("o"));
		// the second arguments specified the start index
		// where to start looking.
		// in this case, the index of the first "o" 
		// starting from the index 5 (space in our case) 
		// is found.
		System.out.println(s.indexOf("o", 5));
		
		// substring returns a string, which
		// starts at the given index
		// and ends *before* the second index.
		
		// if only one argument is given,
		// returned substring starts from the
		// given index and ends at the end
		// of the string itself.
		System.out.println(s.substring(6));
		// here index 6 is inclusive, 8 is exclusive
		System.out.println(s.substring(6, 8));
		
	}
}
